<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Promise </title>
</head>

<body>
    <script>
        let checkLogin = () => {
            return new Promise((resolve, reject) => {
                let flag = document.cookie.indexOf("userId") > -1 ? true : false;

                if (falg = true) {
                    resolve({
                        status: 0,
                        result: true
                    })
                } else {
                    reject("error");
                }

            })
        };

        let getUserIdInfo = () => {
            return new Promise((resolve,reject) => {
                let userInfo = {
                    userId : "101"
                }
                resolve(userInfo);
            });
        }

        checkLogin().then((res) => {
            if (res.status == 0) {
                console.log("login success");
                return getUserIdInfo();
            }
        }).catch((error) => {
            console.log(`error:${error}`);
        }).then((res2) => {
            console.log(`userId:${res2.userId}`);
        });

        Promise.all([checkLogin(),getUserIdInfo()]).then(([res1,res2]) => {
            console.log(`result1:${res1.result},result2:${res2.userId}`);
        })
    </script>
</body>

</html>